﻿using System;
using System.Globalization;
using System.ComponentModel;
using System.Collections;
using System.Collections.Generic;
using System.Linq;
using System.Text;
using System.Reflection;
using Microsoft.SharePoint;

namespace Core.Foundation.Standards
{
    public static class FoundationConstants
    {
        public const string BaseName = "MAGDEV";

        // app config
        
        public static readonly string CoreSite = "/" + BaseName + "/Core";
        public static readonly string AppConfigListName = "AppConfig";
        public static readonly string AppConfigContentTypeName = "AppConfig";
        public static readonly string AppConfigVersioningGroup = "Version";
        public static readonly string AppConfigVersioningSolutionKey = "Solution";

        // site columns and content type
        public const string SiteColumnListName = "SiteColumns";
        public const string ContentTypeListName = "ContentTypes";
        public const string ItemContentTypeName = "Item";

        public const string SiteColumnGroup = BaseName + "Foundation Columns";
        public const string ContentTypeGroup = BaseName + "Foundation Content Types";

        public const string FieldDesc = BaseName + " Code Dependent - Do Not Modify";
        public const string ListDesc = BaseName + " Code Dependent. The values in this list are used by other " + BaseName + " components.";


        public const FoundationAppConfig.LoggingCategories coreLog = FoundationAppConfig.LoggingCategories.Core;
        public const FoundationAppConfig.LoggingCategories standardsLog = FoundationAppConfig.LoggingCategories.Standards;
        public const FoundationAppConfig.LoggingCategories webpartsLog = FoundationAppConfig.LoggingCategories.WebParts;
        public const FoundationAppConfig.LoggingCategories featuresLog = FoundationAppConfig.LoggingCategories.Features; 
    }


    /// <summary>
    /// Enums
    /// </summary>
    public class FoundationEnums
    {
        public static Nullable<T> StringToEnum<T>(string value) where T : struct
        {
            string[] names = Enum.GetNames(typeof(T));
            if (((IList)names).Contains(value))
            {
                return (T)Enum.Parse(typeof(T), value);
            }
            return null;
        }

        public enum FieldTypes
        {
            Integer = SPFieldType.Integer,
            Text = SPFieldType.Text,
            Note = SPFieldType.Note,
            DateTime = SPFieldType.DateTime,
            Choice = SPFieldType.Choice,
            Lookup = SPFieldType.Lookup,
            Boolean = SPFieldType.Boolean,
            URL = SPFieldType.URL,
            Calculated = SPFieldType.Calculated,
            TaxonomyFieldType = 100 // since there is no SPFieldType allocated to TaxonomyFieldType, added 100 to it.
        }

        public enum Format
        {
            Hyperlink,
            Picture,
            DateOnly,
            DateTime,
            NoFormat
        }
    }



    public class FoundationContentTypeID
    {
        /// <summary>
        /// AppConfig inherited from Item Content Type <Guid("FB513D29-3180-4EF7-B424-5F61DB76B538")>
        /// </summary>
        public static readonly string AppConfig = "0x0100FB513D2931804EF7B4245F61DB76B538";

    }

    public static class FoundationColumnID
    {
        /// <summary>
        /// AppConfig Content Type
        /// </summary>
        public static readonly Guid Module = new Guid("{0B9A3CC1-0059-4C52-9F65-F84EE467FADE}");
        /// <summary>
        /// AppConfig Content Type 
        /// </summary>
        public static readonly Guid Group = new Guid("{2D02F960-6393-4229-9610-47E53A385FA5}");
        /// <summary>
        /// AppConfig Content Type 
        /// </summary>
        public static readonly Guid Key = new Guid("{A84F3429-D611-414C-AF38-BA6CB52F0F75}");
        /// <summary>
        /// AppConfig Content Type 
        /// </summary>
        public static readonly Guid Value = new Guid("{BCE5511D-6A87-47D1-9355-91BB25F36D0D}");
        /// <summary>
        /// AppConfig Content Type
        /// </summary>
        public static readonly Guid Active = new Guid("{BD67938A-9160-4ABB-89DE-D4C4E7AD3292}");
        /// <summary>
        /// AppConfig Content Type
        /// </summary>
        public static readonly Guid Version = new Guid("{BF59F18F-3F0F-4310-9D31-B2E3094E6905}");
        /// <summary>
        /// AppConfig Content Type
        /// </summary>
        public static readonly Guid Encrypted = new Guid("{DA5A8B7D-F436-402D-9C2A-2C11075DAA48}");
    }




    /// <summary>
    /// Application Configuration Settings for Core.Foundation
    /// </summary>
    public class FoundationAppConfig : AppConfig.Attributes
    {
        public const string Module = FoundationConstants.BaseName + " Foundation";

        /// <summary>
        /// Application Configuration for Logging Categories
        /// </summary>
        private const string LoggingCategoriesGroup = "Logging";
        private const string LoggingCategoriesKey = "Category";
        public enum LoggingCategories
        {

            [AppConfigModule(Module)]
            [AppConfigGroup(LoggingCategoriesGroup)]
            [AppConfigKey(LoggingCategoriesKey)]
            [AppConfigValue("Core")]
            [AppConfigActive(true)]
            Core,
            [AppConfigModule(Module)]
            [AppConfigGroup(LoggingCategoriesGroup)]
            [AppConfigKey(LoggingCategoriesKey)]
            [AppConfigValue("Features")]
            [AppConfigActive(true)]
            Features,
            [AppConfigModule(Module)]
            [AppConfigGroup(LoggingCategoriesGroup)]
            [AppConfigKey(LoggingCategoriesKey)]
            [AppConfigValue("Standards")]
            [AppConfigActive(true)]
            Standards,
            [AppConfigModule(Module)]
            [AppConfigGroup(LoggingCategoriesGroup)]
            [AppConfigKey(LoggingCategoriesKey)]
            [AppConfigValue("WebParts")]
            [AppConfigActive(true)]
            WebParts
        }


       

    }
}